package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.reggie.entity.DishFlavor;
import com.itheima.reggie.mapper.DishFlavorMapper;
import com.itheima.reggie.service.DishFlavorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DishFlavorServiceImpl implements DishFlavorService {

    @Autowired
    private DishFlavorMapper mapper;

    /**
     * 添加口味数据
     *
     * @param dishFlavor
     * @return
     */
    @Override
    public int add(DishFlavor dishFlavor) {
        return mapper.insert(dishFlavor);
    }

    /**
     * 根据菜品id,查询菜品口味数据
     *
     * @param dishId
     * @return
     */
    @Override
    public List<DishFlavor> findByDishId(long dishId) {
        //设置查询条件
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId, dishId);

        return mapper.selectList(lqw);
    }

    /**
     * 根据id删除口味
     *
     * @param dishId
     * @return
     */
    @Override
    public int delete(long dishId) {

        //设置查询条件
        LambdaQueryWrapper<DishFlavor> lqw = new LambdaQueryWrapper<>();
        lqw.eq(DishFlavor::getDishId, dishId);

        return mapper.delete(lqw);
    }


}
